from typing import List
from random import SystemRandom


class Game:
    active_games = {}
    MIN_COST = 5
    MAX_COST = 1000

    def __init__(self, inline_message_id, cost, creator, creator_name):
        self.inline_message_id = inline_message_id
        self.cost = cost
        self.started = False
        self.creator = creator
        self.creator_name = creator_name
        self.opponent = None
        self.finished = False
        self.result = []

    def setOpponent(self, opponent, name):
        self.opponent = opponent
        self.opponent_name = name

    def setStarted(self, status):
        self.started = status

    def isStarted(self):
        return self.started

    def isCreator(self, somebody):
        return self.creator == somebody

    def changeCost(self, action):
        if action == 'btnDivTen':
            self.cost //= 10
        elif action == 'btnMinusFive':
            self.cost -= 5
        elif action == 'btnPlusFive':
            self.cost += 5
        elif action == 'btnMulTen':
            self.cost *= 10
        else:
            pass
        if self.cost < Game.MIN_COST:
            self.cost = Game.MIN_COST
        if self.cost >= Game.MAX_COST:
            self.cost = Game.MAX_COST
        return self.cost

    @staticmethod
    def appendNewGame(inline_message_id, cost, creator, name):
        game = Game(inline_message_id, cost, creator, name)
        Game.active_games[inline_message_id] = game

    @staticmethod
    def getGameByInline(inline_message_id):
        try:
            return Game.active_games[inline_message_id]
        except:
            return None

    def pickWinner(self):
        cryptogen = SystemRandom()
        result = [[cryptogen.randrange(1, 7) for i in range(3)], [
            cryptogen.randrange(1, 7) for i in range(3)]]
        self.finished = True
        self.result = result
        return result
